package com.drdj.exam;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Vibrator;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class Vibrate extends Activity {
	
	private Vibrator mVibrator;
	private Button mBtnStart;
	private Button mBtnStartPattern;
	private Button mBtnStop;


	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		setContentView(R.layout.vibration);
		
		/*
		 * get Vibrator from system service.
		 * don't forget : add VIBRATE permission to AndroidMenifest.xml
		 */
		mVibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
		
		/*
		 * Turn the vibrator on. 
		 */
		mBtnStart = (Button) findViewById(R.id.btnStartVibrate);
		mBtnStart.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// vibrate for specified time(millisecond).
				mVibrator.vibrate(10000);
			}
		});

		/*
		 * Turn the vibrator on with pattern. 
		 */
		mBtnStartPattern = (Button) findViewById(R.id.btnStartVibratePattern);
		mBtnStartPattern.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// vibrate with specified pattern.
				mVibrator.vibrate(new long[]{100, 100, 100, 100, 100, 500}, -1);
			}
		});

		/*
		 * turn the vibrator off. 
		 */
		mBtnStop = (Button) findViewById(R.id.btnStopVibrate);
		mBtnStop.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mVibrator.cancel();
			}
		});

	}
}
